﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using GameEngine.SceneGraph;

namespace Redland2
{
    class Tile : Entity 
    {
        #region members

        public int tileType;

        #endregion members

        #region properties
        #endregion properties

        #region constructors
        public Tile(GameScene inputScene, int inputIndex, Vector2 inputPos, int inputType): base(inputScene, inputIndex, GameScene.Current.Content.Load<Texture2D>("Wall"), inputPos)
        {
            SetupTile();
            tileType = inputType;
            this.type = "tile";
            switch (tileType)
            {
                case 1:
                    this.Texture = GameScene.Current.Content.Load<Texture2D>("Wall");
                    this.type = "wall";
                    break;

                case 2:
                    this.Texture = GameScene.Current.Content.Load<Texture2D>("Lava");
                    this.type = "lava";
                    break;
                case 3:
                    this.Texture = GameScene.Current.Content.Load<Texture2D>("Pit");
                    this.type = "hole";
                    break;
            }
            
        }

        private void SetupTile()
        {
            this.SetOffset(GameEngine.Drawables.Anchor.Center);
        }

        public override bool offscreen()
        {
            return false; // YAY CHEATING -- keep gamescene.CleanUp from removing tiles
        }
        #endregion construcors

        #region methods
        public override void HandleCollision()
        {
            if ( tileType == 3)
                foreach (Entity entity in _collisions)
                    if(entity.type != "bullet")
                        entity.Kill();

            if (tileType == 2 )
                foreach (Entity entity in _collisions)
                    if (entity.type == "player")
                    {
                        Player tempPlayer = (Player)entity;
                        tempPlayer.Health--;
                    }
            base.HandleCollision();
        }
        #endregion method
    }
}
